package com.zt.action.code;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.sql.DataSource;

import org.apache.struts2.json.annotations.JSON;
import org.springframework.jdbc.support.rowset.SqlRowSetMetaData;

import com.zt.action.base.BaseAction;
import com.zt.service.code.IGenJdbcCodeService;

/**
 * Action类 GenJdbcCodeAction
 * 
 * @author zhangzhw
 * @describe 生成代码的Action 类
 */
public class GenJdbcCodeAction extends BaseAction {

	// 返回值
	public boolean success = true;
	// public SqlRowSetMetaData sqlRowSetMetaData;
	public Map<String, List<Object>> map;

	// 注入值
	public IGenJdbcCodeService iGenJdbcCodeService;

	// 前台参数
	public String sql;

	public String jdbcUrl;
	public String user;
	public String password;

	/**
	 * genMetaData
	 * 
	 * @return 列属性
	 */
	public String genMetaData() {

		map = iGenJdbcCodeService.getMetaData(sql);

		return SUCCESS;

	}

	public String testDataSource() throws Exception {

		DataSource ds = iGenJdbcCodeService.testDataSource(jdbcUrl, user,
				password);

		if (ds != null) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("ds", ds);
		}

		return SUCCESS;
	}

	// getters and setters
	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	// public SqlRowSetMetaData getSqlRowSetMetaData() {
	// return sqlRowSetMetaData;
	// }
	//
	// public void setSqlRowSetMetaData(SqlRowSetMetaData sqlRowSetMetaData) {
	// this.sqlRowSetMetaData = sqlRowSetMetaData;
	// }

	@JSON(serialize = false)
	public IGenJdbcCodeService getiGenJdbcCodeService() {
		return iGenJdbcCodeService;
	}

	public void setiGenJdbcCodeService(IGenJdbcCodeService iGenJdbcCodeService) {
		this.iGenJdbcCodeService = iGenJdbcCodeService;
	}

	public String getSql() {
		return sql;
	}

	public void setSql(String sql) {
		this.sql = sql;
	}

	public String getJdbcUrl() {
		return jdbcUrl;
	}

	public void setJdbcUrl(String jdbcUrl) {
		this.jdbcUrl = jdbcUrl;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Map<String, List<Object>> getMap() {
		return map;
	}

	public void setMap(Map<String, List<Object>> map) {
		this.map = map;
	}

}
